var video;

//初始化
function init() {
    video = document.getElementById('curVideo');

    var output = document.createElement('div');
    output.style.cssText = 'font-size: 50px;';
    var target = document.getElementById('target');
    target.appendChild(output);

    video.addEventListener('play', function() {
        console.log(this.duration);
        new TWEEN.Tween( { x: 50, y: 0 } )
            .to( { x: 400 }, this.duration )
            .easing( TWEEN.Easing.Linear.None )
            .onUpdate( function (obj) {
                var roundX = Math.round(obj.x);
                var transform = 'translateX(' + roundX + 'px)';
                output.innerHTML = 'x == ' + roundX;
                target.style.transform = transform;
            })
            .start(video.currentTime);
    }, false);

    video.addEventListener('loadedmetadata', function() {
        video.play();
    })
    
}

//动画函数
function animate() {
    requestAnimationFrame(animate);

    if(video.readyState === video.HAVE_ENOUGH_DATA ) {
        TWEEN.update(video.currentTime);
    }
}
    

init();
animate();